package cn.china.xfood.acpect;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Aspect /*声明该类是一个切面*/
public class orderAspect {

    @Pointcut("execution(* cn.china.xfood.controller.OrderController.userOrder(..))")
    public void declearJoinPointExpression(){
    }


    @Autowired
    RedisTemplate redisTemplate;

    @AfterReturning(value="declearJoinPointExpression()",returning="result")
    public void afterReturnMethod(JoinPoint joinPoint, Object result){
        String s = result.toString();
        if ("提交成功".equals(s)){
            Object[] args = joinPoint.getArgs();
            String s1 = args[1].toString();

            redisTemplate.opsForList().getOperations().delete(s1);
        }


    }


}
